#include <stdio.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/un.h>


int client_creat(int* sockfd){
    *sockfd = socket(AF_UNIX,SOCK_STREAM,0);//ipv4,tcp
    if(*sockfd == -1){
        perror("sock err");
        return -1;
    }
    //服务器地址:IP 端口号
    struct sockaddr_un server_addr;
    server_addr.sun_family = AF_UNIX;
    strcpy(server_addr.sun_path,"../sever/mysocket");
    socklen_t addrlen= sizeof(server_addr);
    

    //连接
    if(connect(*sockfd,(struct sockaddr*)&server_addr,addrlen) < 0){
        perror("coonet err");
        close(*sockfd);
        return -1;
    }
    printf("connet  success\n");

    return 0;
}

int main(int argc, char const *argv[])
{
    int n=5;
    int sockfd=-1;
    char buf[64] = "abcdefg";
	

    if(client_creat(&sockfd) < 0){
        return -1;
    }
    if (send(sockfd, buf, 64, 0) == -1){
        perror("send err");
    }
    
    close(sockfd);

    return 0;
}
